package project.proto;

import java.io.*;

/**
 * Created with IntelliJ IDEA.
 * User: leep
 * Date: 15-8-22
 * Time: 下午3:45
 * To change this template use File | Settings | File Templates.
 */
public class Prototype implements Cloneable, Serializable {
	private static final long serialVersionUID = 1L;

	/**
	 * shallow clone;
	 */
	public Prototype clone() throws CloneNotSupportedException {
		Prototype prototype = (Prototype) super.clone();
		return prototype;
	}

	/**
	 * deep clone
	 */

	public Prototype deepClone() throws IOException, ClassNotFoundException {
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		ObjectOutputStream oos = new ObjectOutputStream(baos);
		oos.writeObject(this);
		ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
		ObjectInputStream ois = new ObjectInputStream(bais);
		return (Prototype) ois.readObject();
	}
}
